﻿<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%@ page import="com.tenpay.ResponseHandler"%>   
<%@page import="com.tenpay.util.TenpayUtil"%> 
<%
TenpayUtil.logResult("=========return_url page begin=============");
%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户个人中心-支付</title>
<link href="${ctx }/style/common.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#main{margin: 0 auto;width: 960px;background-color: #ffffff;min-height: 450px;border: 1px solid #ccc;margin-top: 5px;}
</style>
<script type="text/javascript">
function tobuy(){
	location.href = "${ctx}/index.jsp";
}

function toMember(){
	location.href = "${ctx}/customer/customerAction!index.do";
}
</script>
</head>
<body>

	<%@include file="/commons/head.jsp"%>
	
<div id="main">
	
	<div style="margin: 0 auto;width: 830px;padding: 35px 0px 0px 0px;">
		<div style="float: right;"><img src="${ctx }/images/order/order_step4.png" border="0"/></div>
		<div style="float: right;padding-top: 5px;">订购流程:</div>
		<div style="clear: both;"></div>
	</div>
<%
//---------------------------------------------------------
//财付通支付应答（处理回调）示例，商户按照此文档进行开发即可
//---------------------------------------------------------
//密钥
String key = "yq36050219761201rx43042619790811";

//创建支付应答对象
ResponseHandler resHandler = new ResponseHandler(request, response);
resHandler.setKey(key);

//判断签名
if(resHandler.isTenpaySign()) {

        //通知id
	String notify_id = resHandler.getParameter("notify_id");
	
	//商户订单号
	String out_trade_no = resHandler.getParameter("out_trade_no");
	
	//财付通订单号
	String transaction_id = resHandler.getParameter("transaction_id");
	
	//金额,以分为单位
	String total_fee = resHandler.getParameter("total_fee");
	
	double fee = Double.valueOf(total_fee).doubleValue()/100.00;
	
	//如果有使用折扣券，discount有值，total_fee+discount=原请求的total_fee
	String discount = resHandler.getParameter("discount");
	
	//支付结果
	String trade_state = resHandler.getParameter("trade_state");
	
	String trade_mode = resHandler.getParameter("trade_mode");
	
	if( "0".equals(trade_state) && "1".equals(trade_mode) ) {
		//------------------------------
		//处理业务开始
		//------------------------------ 
		
		//注意交易单不要重复处理
		//注意判断返回金额
		
		//------------------------------
		//处理业务完毕
		//------------------------------
		TenpayUtil.logResult("return_url page TRADE_FINISHED or TRADE_SUCCESS");
%>
<div style="margin: 0 auto;width: 830px;font-size: 22px;color:#fd7602;padding:75px 0px 0px 0px; font-family: 黑体;">订单支付成功！我们将尽快安排为您发货。</div>
<div style="padding: 40px 0px;font-size: 14px;text-align: center;"><span>订单号：<%=out_trade_no %></span><span style="padding-left: 50px;">已付金额：<%=fee %>元</span></div>
<%
	} else {
		TenpayUtil.logResult("return_url ===== 支付失败！");
%>
<div style="margin: 0 auto;width: 830px;font-size: 22px;color:#fd7602;padding:75px 0px 0px 0px; font-family: 黑体;">支付失败！</div>
<%
	}
} else {
	TenpayUtil.logResult("return_url ===== 验证失败！");
%>
<div style="margin: 0 auto;width: 830px;font-size: 22px;color:#fd7602;padding:75px 0px 0px 0px; font-family: 黑体;">验证失败！</div>
<%
}
//获取debug信息,建议把debug信息写入日志，方便定位问题
//String debuginfo = resHandler.getDebugInfo();
//System.out.println("debuginfo:" + debuginfo);
TenpayUtil.logResult("=========return_url page end=============");
%>
<div style="text-align: center;padding: 50px 0px 0px 0px;">
	<span><input type="button" value="继续选购" onclick="tobuy()" style="padding: 8px 5px;cursor: hand;"/></span>
	<span style="padding-left: 20px;">
		<input type="button" value="我的订购" onclick="toMember()" style="padding: 8px 5px;cursor: hand;"/>
	</span>
</div>
</div>

<%@ include file="/commons/foot.jsp" %>

  </body>
</html>
